using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace CDTM.Modules.TraCuuDiem.Components
{
	public partial class KQHocTap
	{
		#region Properties.
		
		public string MaSV { set; get; }
		public string HoTenLot { set; get; }
		public string Ten { set; get; }
		public string Lop { set; get; }
		public double HT_TBC { set; get; }
		public string HT_XepLoai { set; get; }
		public double RL_TDiem { set; get; }
		public string RL_XepLoai { set; get; }
		public int Mon1 { set; get; }
		public int Mon2 { set; get; }
		public int Mon3 { set; get; }
		public int Mon4 { set; get; }
		public int Mon5 { set; get; }
		public int Mon6 { set; get; }
		public int Mon7 { set; get; }
		public int Mon8 { set; get; }
		public int Mon9 { set; get; }
		public string DHTDNH { set; get; }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static KQHocTap Load(string maSV)
		{
			const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_Load]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@MaSV", SqlDbType.NVarChar, maSV);
			KQHocTap entity = null;
            IDataReader reader = db.ExecuteReader(dbCommand);
			if (reader.Read())
			{
				entity = new KQHocTap();
				if (!reader.IsDBNull(reader.GetOrdinal("MaSV"))) entity.MaSV = reader.GetString(reader.GetOrdinal("MaSV"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoTenLot"))) entity.HoTenLot = reader.GetString(reader.GetOrdinal("HoTenLot"));
				if (!reader.IsDBNull(reader.GetOrdinal("Ten"))) entity.Ten = reader.GetString(reader.GetOrdinal("Ten"));
				if (!reader.IsDBNull(reader.GetOrdinal("Lop"))) entity.Lop = reader.GetString(reader.GetOrdinal("Lop"));
				if (!reader.IsDBNull(reader.GetOrdinal("HT_TBC"))) entity.HT_TBC = reader.GetDouble(reader.GetOrdinal("HT_TBC"));
				if (!reader.IsDBNull(reader.GetOrdinal("HT_XepLoai"))) entity.HT_XepLoai = reader.GetString(reader.GetOrdinal("HT_XepLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("RL_TDiem"))) entity.RL_TDiem = reader.GetDouble(reader.GetOrdinal("RL_TDiem"));
				if (!reader.IsDBNull(reader.GetOrdinal("RL_XepLoai"))) entity.RL_XepLoai = reader.GetString(reader.GetOrdinal("RL_XepLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon1"))) entity.Mon1 = reader.GetInt32(reader.GetOrdinal("Mon1"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon2"))) entity.Mon2 = reader.GetInt32(reader.GetOrdinal("Mon2"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon3"))) entity.Mon3 = reader.GetInt32(reader.GetOrdinal("Mon3"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon4"))) entity.Mon4 = reader.GetInt32(reader.GetOrdinal("Mon4"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon5"))) entity.Mon5 = reader.GetInt32(reader.GetOrdinal("Mon5"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon6"))) entity.Mon6 = reader.GetInt32(reader.GetOrdinal("Mon6"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon7"))) entity.Mon7 = reader.GetInt32(reader.GetOrdinal("Mon7"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon8"))) entity.Mon8 = reader.GetInt32(reader.GetOrdinal("Mon8"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon9"))) entity.Mon9 = reader.GetInt32(reader.GetOrdinal("Mon9"));
				if (!reader.IsDBNull(reader.GetOrdinal("DHTDNH"))) entity.DHTDNH = reader.GetString(reader.GetOrdinal("DHTDNH"));
			}
			reader.Close();
			return entity;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static List<KQHocTap> SelectCollectionAll()
		{
			List<KQHocTap> collection = new List<KQHocTap>();
			SqlDataReader reader = (SqlDataReader) SelectReaderAll();
			while (reader.Read())
			{
				KQHocTap entity = new KQHocTap();
				
				if (!reader.IsDBNull(reader.GetOrdinal("MaSV"))) entity.MaSV = reader.GetString(reader.GetOrdinal("MaSV"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoTenLot"))) entity.HoTenLot = reader.GetString(reader.GetOrdinal("HoTenLot"));
				if (!reader.IsDBNull(reader.GetOrdinal("Ten"))) entity.Ten = reader.GetString(reader.GetOrdinal("Ten"));
				if (!reader.IsDBNull(reader.GetOrdinal("Lop"))) entity.Lop = reader.GetString(reader.GetOrdinal("Lop"));
				if (!reader.IsDBNull(reader.GetOrdinal("HT_TBC"))) entity.HT_TBC = reader.GetDouble(reader.GetOrdinal("HT_TBC"));
				if (!reader.IsDBNull(reader.GetOrdinal("HT_XepLoai"))) entity.HT_XepLoai = reader.GetString(reader.GetOrdinal("HT_XepLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("RL_TDiem"))) entity.RL_TDiem = reader.GetDouble(reader.GetOrdinal("RL_TDiem"));
				if (!reader.IsDBNull(reader.GetOrdinal("RL_XepLoai"))) entity.RL_XepLoai = reader.GetString(reader.GetOrdinal("RL_XepLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon1"))) entity.Mon1 = reader.GetInt32(reader.GetOrdinal("Mon1"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon2"))) entity.Mon2 = reader.GetInt32(reader.GetOrdinal("Mon2"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon3"))) entity.Mon3 = reader.GetInt32(reader.GetOrdinal("Mon3"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon4"))) entity.Mon4 = reader.GetInt32(reader.GetOrdinal("Mon4"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon5"))) entity.Mon5 = reader.GetInt32(reader.GetOrdinal("Mon5"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon6"))) entity.Mon6 = reader.GetInt32(reader.GetOrdinal("Mon6"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon7"))) entity.Mon7 = reader.GetInt32(reader.GetOrdinal("Mon7"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon8"))) entity.Mon8 = reader.GetInt32(reader.GetOrdinal("Mon8"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon9"))) entity.Mon9 = reader.GetInt32(reader.GetOrdinal("Mon9"));
				if (!reader.IsDBNull(reader.GetOrdinal("DHTDNH"))) entity.DHTDNH = reader.GetString(reader.GetOrdinal("DHTDNH"));
				collection.Add(entity);
			}
			
			reader.Close();
			return collection;			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static List<KQHocTap> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			List<KQHocTap> collection = new List<KQHocTap>();

			SqlDataReader reader = (SqlDataReader) SelectReaderDynamic(whereCondition, orderByExpression);
			while (reader.Read())
			{
				KQHocTap entity = new KQHocTap();
				
				if (!reader.IsDBNull(reader.GetOrdinal("MaSV"))) entity.MaSV = reader.GetString(reader.GetOrdinal("MaSV"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoTenLot"))) entity.HoTenLot = reader.GetString(reader.GetOrdinal("HoTenLot"));
				if (!reader.IsDBNull(reader.GetOrdinal("Ten"))) entity.Ten = reader.GetString(reader.GetOrdinal("Ten"));
				if (!reader.IsDBNull(reader.GetOrdinal("Lop"))) entity.Lop = reader.GetString(reader.GetOrdinal("Lop"));
				if (!reader.IsDBNull(reader.GetOrdinal("HT_TBC"))) entity.HT_TBC = reader.GetDouble(reader.GetOrdinal("HT_TBC"));
				if (!reader.IsDBNull(reader.GetOrdinal("HT_XepLoai"))) entity.HT_XepLoai = reader.GetString(reader.GetOrdinal("HT_XepLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("RL_TDiem"))) entity.RL_TDiem = reader.GetDouble(reader.GetOrdinal("RL_TDiem"));
				if (!reader.IsDBNull(reader.GetOrdinal("RL_XepLoai"))) entity.RL_XepLoai = reader.GetString(reader.GetOrdinal("RL_XepLoai"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon1"))) entity.Mon1 = reader.GetInt32(reader.GetOrdinal("Mon1"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon2"))) entity.Mon2 = reader.GetInt32(reader.GetOrdinal("Mon2"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon3"))) entity.Mon3 = reader.GetInt32(reader.GetOrdinal("Mon3"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon4"))) entity.Mon4 = reader.GetInt32(reader.GetOrdinal("Mon4"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon5"))) entity.Mon5 = reader.GetInt32(reader.GetOrdinal("Mon5"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon6"))) entity.Mon6 = reader.GetInt32(reader.GetOrdinal("Mon6"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon7"))) entity.Mon7 = reader.GetInt32(reader.GetOrdinal("Mon7"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon8"))) entity.Mon8 = reader.GetInt32(reader.GetOrdinal("Mon8"));
				if (!reader.IsDBNull(reader.GetOrdinal("Mon9"))) entity.Mon9 = reader.GetInt32(reader.GetOrdinal("Mon9"));
				if (!reader.IsDBNull(reader.GetOrdinal("DHTDNH"))) entity.DHTDNH = reader.GetString(reader.GetOrdinal("DHTDNH"));
				collection.Add(entity);
			}
			
			reader.Close();
			return collection;			
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_SelectAll]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_SelectDynamic]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_SelectAll]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_SelectDynamic]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static int InsertKQHocTap(string hoTenLot, string ten, string lop, double hT_TBC, string hT_XepLoai, double rL_TDiem, string rL_XepLoai, int mon1, int mon2, int mon3, int mon4, int mon5, int mon6, int mon7, int mon8, int mon9, string dHTDNH)
		{
			KQHocTap entity = new KQHocTap();	
			entity.HoTenLot = hoTenLot;
			entity.Ten = ten;
			entity.Lop = lop;
			entity.HT_TBC = hT_TBC;
			entity.HT_XepLoai = hT_XepLoai;
			entity.RL_TDiem = rL_TDiem;
			entity.RL_XepLoai = rL_XepLoai;
			entity.Mon1 = mon1;
			entity.Mon2 = mon2;
			entity.Mon3 = mon3;
			entity.Mon4 = mon4;
			entity.Mon5 = mon5;
			entity.Mon6 = mon6;
			entity.Mon7 = mon7;
			entity.Mon8 = mon8;
			entity.Mon9 = mon9;
			entity.DHTDNH = dHTDNH;
			return entity.Insert();
		}
		
		public int Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public int Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_Insert]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@MaSV", SqlDbType.NVarChar, MaSV);
			db.AddInParameter(dbCommand, "@HoTenLot", SqlDbType.NVarChar, HoTenLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@Lop", SqlDbType.NVarChar, Lop);
			db.AddInParameter(dbCommand, "@HT_TBC", SqlDbType.Float, HT_TBC);
			db.AddInParameter(dbCommand, "@HT_XepLoai", SqlDbType.NVarChar, HT_XepLoai);
			db.AddInParameter(dbCommand, "@RL_TDiem", SqlDbType.Float, RL_TDiem);
			db.AddInParameter(dbCommand, "@RL_XepLoai", SqlDbType.NVarChar, RL_XepLoai);
			db.AddInParameter(dbCommand, "@Mon1", SqlDbType.Int, Mon1);
			db.AddInParameter(dbCommand, "@Mon2", SqlDbType.Int, Mon2);
			db.AddInParameter(dbCommand, "@Mon3", SqlDbType.Int, Mon3);
			db.AddInParameter(dbCommand, "@Mon4", SqlDbType.Int, Mon4);
			db.AddInParameter(dbCommand, "@Mon5", SqlDbType.Int, Mon5);
			db.AddInParameter(dbCommand, "@Mon6", SqlDbType.Int, Mon6);
			db.AddInParameter(dbCommand, "@Mon7", SqlDbType.Int, Mon7);
			db.AddInParameter(dbCommand, "@Mon8", SqlDbType.Int, Mon8);
			db.AddInParameter(dbCommand, "@Mon9", SqlDbType.Int, Mon9);
			db.AddInParameter(dbCommand, "@DHTDNH", SqlDbType.NVarChar, DHTDNH);
			
			if (transaction != null)
			{
				return db.ExecuteNonQuery(dbCommand, transaction);
			}
            else
			{
				return db.ExecuteNonQuery(dbCommand);
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(IList<KQHocTap> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (KQHocTap item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateKQHocTap(string maSV, string hoTenLot, string ten, string lop, double hT_TBC, string hT_XepLoai, double rL_TDiem, string rL_XepLoai, int mon1, int mon2, int mon3, int mon4, int mon5, int mon6, int mon7, int mon8, int mon9, string dHTDNH)
		{
			KQHocTap entity = new KQHocTap();			
			entity.MaSV = maSV;
			entity.HoTenLot = hoTenLot;
			entity.Ten = ten;
			entity.Lop = lop;
			entity.HT_TBC = hT_TBC;
			entity.HT_XepLoai = hT_XepLoai;
			entity.RL_TDiem = rL_TDiem;
			entity.RL_XepLoai = rL_XepLoai;
			entity.Mon1 = mon1;
			entity.Mon2 = mon2;
			entity.Mon3 = mon3;
			entity.Mon4 = mon4;
			entity.Mon5 = mon5;
			entity.Mon6 = mon6;
			entity.Mon7 = mon7;
			entity.Mon8 = mon8;
			entity.Mon9 = mon9;
			entity.DHTDNH = dHTDNH;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "p_CDTM_TCD_KQHocTap_InsertUpdate";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@MaSV", SqlDbType.NVarChar, MaSV);
			db.AddInParameter(dbCommand, "@HoTenLot", SqlDbType.NVarChar, HoTenLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@Lop", SqlDbType.NVarChar, Lop);
			db.AddInParameter(dbCommand, "@HT_TBC", SqlDbType.Float, HT_TBC);
			db.AddInParameter(dbCommand, "@HT_XepLoai", SqlDbType.NVarChar, HT_XepLoai);
			db.AddInParameter(dbCommand, "@RL_TDiem", SqlDbType.Float, RL_TDiem);
			db.AddInParameter(dbCommand, "@RL_XepLoai", SqlDbType.NVarChar, RL_XepLoai);
			db.AddInParameter(dbCommand, "@Mon1", SqlDbType.Int, Mon1);
			db.AddInParameter(dbCommand, "@Mon2", SqlDbType.Int, Mon2);
			db.AddInParameter(dbCommand, "@Mon3", SqlDbType.Int, Mon3);
			db.AddInParameter(dbCommand, "@Mon4", SqlDbType.Int, Mon4);
			db.AddInParameter(dbCommand, "@Mon5", SqlDbType.Int, Mon5);
			db.AddInParameter(dbCommand, "@Mon6", SqlDbType.Int, Mon6);
			db.AddInParameter(dbCommand, "@Mon7", SqlDbType.Int, Mon7);
			db.AddInParameter(dbCommand, "@Mon8", SqlDbType.Int, Mon8);
			db.AddInParameter(dbCommand, "@Mon9", SqlDbType.Int, Mon9);
			db.AddInParameter(dbCommand, "@DHTDNH", SqlDbType.NVarChar, DHTDNH);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(IList<KQHocTap> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (KQHocTap item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateKQHocTap(string maSV, string hoTenLot, string ten, string lop, double hT_TBC, string hT_XepLoai, double rL_TDiem, string rL_XepLoai, int mon1, int mon2, int mon3, int mon4, int mon5, int mon6, int mon7, int mon8, int mon9, string dHTDNH)
		{
			KQHocTap entity = new KQHocTap();			
			entity.MaSV = maSV;
			entity.HoTenLot = hoTenLot;
			entity.Ten = ten;
			entity.Lop = lop;
			entity.HT_TBC = hT_TBC;
			entity.HT_XepLoai = hT_XepLoai;
			entity.RL_TDiem = rL_TDiem;
			entity.RL_XepLoai = rL_XepLoai;
			entity.Mon1 = mon1;
			entity.Mon2 = mon2;
			entity.Mon3 = mon3;
			entity.Mon4 = mon4;
			entity.Mon5 = mon5;
			entity.Mon6 = mon6;
			entity.Mon7 = mon7;
			entity.Mon8 = mon8;
			entity.Mon9 = mon9;
			entity.DHTDNH = dHTDNH;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_Update]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@MaSV", SqlDbType.NVarChar, MaSV);
			db.AddInParameter(dbCommand, "@HoTenLot", SqlDbType.NVarChar, HoTenLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@Lop", SqlDbType.NVarChar, Lop);
			db.AddInParameter(dbCommand, "@HT_TBC", SqlDbType.Float, HT_TBC);
			db.AddInParameter(dbCommand, "@HT_XepLoai", SqlDbType.NVarChar, HT_XepLoai);
			db.AddInParameter(dbCommand, "@RL_TDiem", SqlDbType.Float, RL_TDiem);
			db.AddInParameter(dbCommand, "@RL_XepLoai", SqlDbType.NVarChar, RL_XepLoai);
			db.AddInParameter(dbCommand, "@Mon1", SqlDbType.Int, Mon1);
			db.AddInParameter(dbCommand, "@Mon2", SqlDbType.Int, Mon2);
			db.AddInParameter(dbCommand, "@Mon3", SqlDbType.Int, Mon3);
			db.AddInParameter(dbCommand, "@Mon4", SqlDbType.Int, Mon4);
			db.AddInParameter(dbCommand, "@Mon5", SqlDbType.Int, Mon5);
			db.AddInParameter(dbCommand, "@Mon6", SqlDbType.Int, Mon6);
			db.AddInParameter(dbCommand, "@Mon7", SqlDbType.Int, Mon7);
			db.AddInParameter(dbCommand, "@Mon8", SqlDbType.Int, Mon8);
			db.AddInParameter(dbCommand, "@Mon9", SqlDbType.Int, Mon9);
			db.AddInParameter(dbCommand, "@DHTDNH", SqlDbType.NVarChar, DHTDNH);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(IList<KQHocTap> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (KQHocTap item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteKQHocTap(string maSV)
		{
			KQHocTap entity = new KQHocTap();
			entity.MaSV = maSV;
			
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_CDTM_TCD_KQHocTap_Delete]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@MaSV", SqlDbType.NVarChar, MaSV);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(IList<KQHocTap> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (KQHocTap item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
	}	
}